//
//  LieDetectionVC.m
//  massage
//
//  Created by 李志权 on 2016/12/16.
//  Copyright © 2016年 李志权. All rights reserved.
//

#import "LieDetectionVC.h"

@interface LieDetectionVC ()
{
    UIView *four;
    UIView *progressView;
}
@end

@implementation LieDetectionVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationItem.title = @"测谎";
    
    UIColor *colorOne = [UIColor colorWithRed:(49/255.0)  green:(255/255.0)  blue:(132/255.0)  alpha:1];
    UIColor *colorTwo = [UIColor colorWithRed:(2/255.0)  green:(200/255.0)  blue:(250/255.0)  alpha:1];
    
    CAGradientLayer *gradientLayer =  [CAGradientLayer layer];
    gradientLayer.frame = CGRectMake(0, 0, self.view.width, self.view.highly-64-49);
    //设置颜色
    [gradientLayer setColors:[NSArray arrayWithObjects:(id)[colorOne CGColor],(id)[colorTwo CGColor], nil]];

    //渐变的方向StartPoint－>EndPoint
    [gradientLayer setStartPoint:CGPointMake(0, 0)];
    [gradientLayer setEndPoint:CGPointMake(1, 1)];
    [self.view.layer addSublayer:gradientLayer];
    
    UIImage *lieDetection = [ImageCompress fixToFillScreenWithImage:PNGIMAGE(@"测谎-back1") width:Width-70];
    
    needleView *needle = [[needleView alloc]initWithFrame:CGRectMake(35, 100, lieDetection.size.width, lieDetection.size.height)];

    [self.view addSubview:needle];
    
    UIImageView *headPortrait = [[UIImageView alloc] initWithFrame:CGRectMake(Width/2-40, needle.YHighly-40, 80, 80)];
    headPortrait.image = PNGIMAGE(@"测谎-pic1");
    [self.view addSubview:headPortrait];
    
    UILabel *falseLable = [[UILabel alloc]initWithFrame:CGRectMake(35, needle.YHighly+15, 55, 55)];
    falseLable.textColor = [UIColor whiteColor];
    falseLable.numberOfLines = 0;
    NSString *str = @"假\n";
    NSString *str1 = @"FALSE";
    NSMutableAttributedString *att = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@%@",str,str1]];
    [att addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(0, str.length) ];
    [att addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(str.length, str1.length)];
    falseLable.attributedText = att;
    falseLable.textColor = [UIColor whiteColor];
    [self.view addSubview:falseLable];
    falseLable.textAlignment = NSTextAlignmentCenter;
    
    UILabel *tureLable = [[UILabel alloc]initWithFrame:CGRectMake(Width-90, needle.YHighly+15, 55, 55)];
    tureLable.textColor = [UIColor whiteColor];
    tureLable.numberOfLines = 0;
    NSString *str2 = @"真\n";
    NSString *str3 = @"TURE";
    NSMutableAttributedString *att1 = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@%@",str2,str3]];
    [att1 addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(0, str2.length) ];
    [att1 addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(str2.length, str3.length)];
    tureLable.attributedText = att1;
    tureLable.textColor = [UIColor whiteColor];
    [self.view addSubview:tureLable];
    tureLable.textAlignment = NSTextAlignmentCenter;
    
    UIView *progressBack = [[UIView alloc]initWithFrame:CGRectMake(35, falseLable.YHighly+70, Width-70, 15)];
    [progressBack setShearRound:7.5 masksToBounds:YES borderWidth:1 borderColor:[UIColor whiteColor]];
    [self.view addSubview:progressBack];
    
    progressView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, progressBack.highly)];
    progressView.backgroundColor = [UIColor whiteColor];
    [progressView setShearRound:progressBack.highly/2 masksToBounds:YES borderWidth:0 borderColor:nil];
    [progressBack addSubview:progressView];
    
    progressView.width = progressBack.width*1;
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)animationStart {
    [UIView animateWithDuration:5 animations:^{
        four.transform = CGAffineTransformMakeRotation(M_PI * 60 / 100.0);
        
    }];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

@implementation needleView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        four = [[UIView alloc] initWithFrame:self.bounds];
        [self addSubview:four];

        UIImage *lieDetection = [ImageCompress fixToFillScreenWithImage:PNGIMAGE(@"测谎-back1") width:Width-70];
        UIImageView *point = [[UIImageView alloc] initWithFrame: CGRectMake(0, 0, self.width, self.highly)];
        point.image = lieDetection;
        [self addSubview:point];
        
        UIImageView  *arrow = [[UIImageView alloc] initWithFrame: CGRectMake(0, 0, Width/2.67, 10)];
        if (Width == 320) {
            arrow.width = 80;
        }
        //    point.backgroundColor = [UIColor redColor];
        arrow.center = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
        arrow.image = [UIImage imageNamed:@"测谎-指针.png"];
        arrow.frame = CGRectMake(arrow.frame.origin.x - 77, arrow.frame.origin.y, arrow.frame.size.width, arrow.frame.size.height);
        [four addSubview:arrow];
        four.Y = self.highly/2-7.5;
//        point.frame = CGRectMake(point.frame.origin.x, arrow.frame.origin.y- arrow.frame.size.width-20, lieDetection.size.width, lieDetection.size.height);
        
        [self performSelector:@selector(animationStart) withObject:self afterDelay:1.0];
    }
    return self;
}
- (void)animationStart {
    [UIView animateWithDuration:75 * 0.027 animations:^{
        four.transform = CGAffineTransformMakeRotation(M_PI * 0 / 100.0);
        
    }];
    
    
}

@end
